class NumArray:

    def __init__(self, nums):
        self.all = 0
        self.left = [0] * len(nums)
        self.right = [0] * len(nums)
        for i in range(len(nums)):
            self.all += nums[i]
            if i == 0:
                continue
            self.left[i] = self.left[i-1] + nums[i-1]
        for i in range(len(nums)-2, -1, -1):
            self.right[i] = self.right[i + 1] + nums[i + 1]

    def sumRange(self, i: int, j: int) -> int:
        return self.all - self.left[i] - self.right[j]

if __name__ == '__main__':
    so = NumArray([-2,0,3,-5,2,-1])
    print(so.sumRange(0,2))
